package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class LoginPage extends AnyPage {
  @FindBy(id = "loginform")
  public  WebElement loginForm;
 
  @FindBy(id = "username")
  public  WebElement userNameField;
  @FindBy(name = "password")
  public  WebElement passwordField;
  @FindBy(name = "submit")
  public  WebElement loginButton;
 
  public boolean isOnLoginPage() {
		return loginForm.isDisplayed();
		
	}

@Override
public void tryToOpen() {
	MyPageFactory.getPage(driver,InternalPage.class).logout();
	
  }


public LoginPage loginWithWrongCredentials(String username, String password) {
	userNameField.clear();
	userNameField.sendKeys(username);

	passwordField.clear();
	passwordField.sendKeys(password);

	loginButton.click();
	
	return MyPageFactory.getPage(driver, LoginPage.class);
	
    //wait.until(visibilityOfElementLocated(By.name("submit"))).click();
   //driver.findElement(By.name("submit")).click();
}


public InternalPage loginWithValidCredentials(String username, String password) {
	userNameField.clear();
	userNameField.sendKeys(username);

	passwordField.clear();
	passwordField.sendKeys(password);

	loginButton.click();
	
	return MyPageFactory.getPage(driver, InternalPage.class);
	
    //wait.until(visibilityOfElementLocated(By.name("submit"))).click();
   //driver.findElement(By.name("submit")).click();
}



}


